<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    protected $guarded = ['id'];
    protected $appends = ['user_status','status_style']; 

    private $statusTxt = [
        
        '1' => ['user'=>'待付款','style'=>'primary'],
    	
        '100' => ['user'=>'已完成','style'=>'success'], 
    	
    ];
   
    public function address()
    {
        return $this->belongsTo(UserAddress::class);
    }

    public function user()
    {
    	return $this->belongsTo(User::class);
    }

    public function products()
    {
    	return $this->hasMany(OrderProduct::class);
    }

    public function getUserStatusAttribute()
    {    	
    	return $this->statusTxt[$this->status]['user'];
    }

   
    public function getStatusStyleAttribute()
    {       
        return $this->statusTxt[$this->status]['style'];
    }

    public function getTotalAmountTxtAttribute()
    {       
        return $this->total_amount/100;
    }

    public function getTotalMoneyTxtAttribute()
    {       
        return $this->total_money/100;
    }

    public function getUserMoneyTxtAttribute()
    {
        return $this->user_money/100;
    }
}
